# Copyright (c) 2020 cgsdfc
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

load("@rules_python//python:defs.bzl", "py_binary")
load("@pip//:requirements.bzl", "requirement")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

py_binary(
    name = "gen_hdr",
    srcs = ["gen_hdr.py"],
)

genrule(
    name = "pp_out_h",
    outs = ["pp_out.h"],
    cmd = "./$(location :gen_hdr) -o $(location :pp_out.h)",
    tools = [":gen_hdr"],
)

py_binary(
    name = "gen_asdl",
    srcs = [
        "asdl.py",
        "asdl_index.py",
        "asdl_unparse.py",
        "gen_asdl.py",
        "license_const.py",
    ],
    data = ["asdl_index.asdl"],
    deps = [requirement("pycparser")],
)

genrule(
    name = "Python_asdl",
    srcs = [":pp_out.h"],
    outs = ["Python.asdl"],
    cmd = "./$(location :gen_asdl) -i $(location pp_out.h) -o $(location Python.asdl)",
    tools = [":gen_asdl"],
)

py_binary(
    name = "gen_data",
    srcs = [
        "asdl.py",
        "cc_types.py",
        "gen_data.py",
    ],
)

genrule(
    name = "data_pkl",
    srcs = ["Python.asdl"],
    outs = ["data.pkl"],
    cmd = "./$(location :gen_data) -i $(location Python.asdl) -o $(location data.pkl)",
    tools = [":gen_data"],
)

py_binary(
    name = "gen_src",
    srcs = [
        "cc_types.py",
        "format_utils.py",
        "gen_src.py",
        "mako_utils.py",
    ],
    deps = [
        requirement("mako"),
    ],
)
